<?php
namespace app\index\controller;


use app\common\lib\Util;
use app\common\lib\Predis;
use app\common\lib\Rekey;

class Login
{
    public function index()
    {
		
		//echo "login";
		//print_r($_POST);
		
		//return "";
		
		
		
		$phone_num = $_POST['phone_num'];
		$code = $_POST['code'];
		
		
		if(empty($phone_num) || empty($code)){
			
			Util::show(0,"错误信息");
			return "";
		}
		
		$re_phone= Rekey::smsKey($phone_num);
		
		
		try {
            $redisCode = Predis::getInstance()->get($re_phone);
			
        }catch (\Exception $e) {
            // echo $e->getMessage();
        }
		
		if($redisCode == $code){
			$user_key =Rekey::userkey($phone_num);
			
			$data = [
                'user' => $phone_num,
                'srcKey' => md5($user_key),
                'time' => time(),
                'isLogin' => true,
            ];
			
			Predis::getInstance()->set($user_key,$data);
			Util::show(1,"验证成功");
		}else{
			
			Util::show(0,"验证失败");
		}
		
		// echo $redisCode ."==".$code;
		
		return "";
		
    }
	
	public function add(){
		echo time();
	}
}
